<?php
include_once("../module/micro_stock/includes/plugin_micro_stock_class.php");
$microStock = new MicroStock();

if(!($_GET['memberId']>0)){
    $memberId = 0;
}else{
    $memberId = $_GET['memberId'];
}

if(isset($_GET['type']) && $_GET['type']=="out"){//出仓记录
    $field = "a.`pid`,a.`num`,a.`stock_shop`,a.`create_time`,a.`order_id`,b.`product_name`,b.`property`,b.`pic`,d.`title` as shop_name,(SELECT SUM(s.`num`) from haiou_micro_stock_out s where a.sku_id=s.sku_id and s.member_id={$memberId}) as total_num";
    $numCond = $cond = " and a.`member_id`={$memberId} ";
    
    if($_GET['stock_shop']){
        $cond .= " and a.`stock_shop`={$_GET['stock_shop']} ";
    }
    if($_GET['product_id']){
        $numCond .= $cond .= " and a.`pid` in(".trim(trim($_GET['product_id']),',').") ";
    }
    if($_GET['stime'])
    {
    	$numCond .= $cond .=" and a.`create_time` >= '".$_GET['stime']."' ";
    }
    if($_GET['etime'])
    {
    	$numCond .= $cond .=" and a.`create_time` <= '".$_GET['etime']."' ";
    }
    
    //=============================
    include_once("../includes/page_utf_class.php");
    $page = new Page;
    $page->listRows=20;
    if (!$page->__get('totalRows')){
        $de['count']=$page->totalRows = $microStock->getMemberOutOfStockRecordsTotalNum($cond);//总数
    }
    $de['count']=$de['count']?$de['count']:($_GET['totalRows']?$_GET['totalRows']:'0');
    $de['page'] = $page->prompt();
    $de['perPageRows'] = $page->listRows;
    //=============================
    
    //列表数据
    $de['list'] = $microStock->getMemberOutOfStockRecords($field,$cond,'',$page->firstRow,$page->listRows);
    //记录数按仓库分
    $de['numByShop'] = $microStock->getMemberOutOfStockRecordsTotalNumByShop($numCond);
}else{//入仓记录
    $field = "c.`pid`,a.`num`,a.`price`,b.`stock_shop`,a.`create_time`,a.`product_name`,a.`property`,a.`pic`,a.`order_id`,d.`title` as shop_name,(SELECT SUM(s.`num`) from haiou_micro_stock_order_product s LEFT JOIN haiou_micro_stock_order o ON o.order_id=s.order_id where a.sku_id=s.sku_id and s.member_id={$memberId} AND o.`status`>1) as total_num";
    $numCond = $cond = " and a.`member_id`={$memberId}";
    
    if($_GET['stock_shop']){
        $cond .= " and b.`stock_shop`={$_GET['stock_shop']} ";
    }
    if($_GET['product_id']){
        $numCond .= $cond .= " and c.`pid` in(".trim(trim($_GET['product_id']),',').") ";
    }
    if($_GET['stime'])
    {
        $numCond .= $cond .=" and a.`create_time` >= '".$_GET['stime']."' ";
    }
    if($_GET['etime'])
    {
        $numCond .= $cond .=" and a.`create_time` <= '".$_GET['etime']."' ";
    }
    
    //=============================
    include_once("../includes/page_utf_class.php");
    $page = new Page;
    $page->listRows=20;
    if (!$page->__get('totalRows')){
        $de['count']=$page->totalRows = $microStock->getMemberPutInStockRecordsTotalNum($cond);//总数
    }
    $de['count']=$de['count']?$de['count']:($_GET['totalRows']?$_GET['totalRows']:'0');
    $de['page'] = $page->prompt();
    $de['perPageRows'] = $page->listRows;
    //=============================
    
    //列表数据
    $de['list'] = $microStock->getMemberPutInStockRecords($field,$cond,'',$page->firstRow,$page->listRows);
    //记录数按仓库分
    $de['numByShop'] = $microStock->getMemberPutInStockRecordsTotalNumByShop($numCond);
}

$tpl->assign('de',$de);
$tpl->display('micro_stock_records.htm');